﻿using Shioho.Net;
using System;

namespace DanmakuGame 
{
    public class DanmakuToolWebsocket : BestHttpWebsocket
    {
        public Action OnOpenEvt;
        public Action OnCloseEvt;
        public Action OnErrorEvt;
        public Action OnSilentReconnectEvt;
        public Action<byte[]> OnReceivedBinaryEvt;
        public Action<string> OnReceivedStringEvt;

        public DanmakuToolWebsocket(string url) : base(url)
        {
        }

        protected override void OnOpen()
        {
            base.OnOpen();
            OnOpenEvt?.Invoke();
        }

        protected override void OnClosed()
        {
            base.OnClosed();
            OnCloseEvt?.Invoke();
        }

        protected override void OnError()
        {
            base.OnError();
            OnErrorEvt?.Invoke();
        }

        protected override void OnSilentReconnect()
        {
            base.OnSilentReconnect();
            OnSilentReconnectEvt?.Invoke();
        }

        protected override void OnReceivedBinary(byte[] buffer)
        {
            base.OnReceivedBinary(buffer);
            OnReceivedBinaryEvt?.Invoke(buffer);
        }

        protected override void OnReceivedString(string message)
        {
            base.OnReceivedString(message);
            OnReceivedStringEvt?.Invoke(message);
        }

    }
}
